package com.lahuan.demo.controller;


import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import com.lahuan.common.Result;
import com.lahuan.demo.service.OrderService;
import com.lahuan.demo.entity.Order;
import javax.validation.Valid;

/**
 * <p>
 *  控制器
 * </p>
 * @author lahuan
 * @since 2021-12-11
 */
@RequiredArgsConstructor
@RestController
@Slf4j
@Api(value = "t_order", tags = "接口")
@RequestMapping("/demo/order")
public class OrderController {

    private final OrderService orderService;

    @ApiOperation(value = "获取分页列表",notes="获取分页列表")
    @GetMapping("")
    public  Result<Page<Order>> orderList(Page< Order> page, Order query) {
        return Result.ok(orderService.page(page, Wrappers.query(query)));
    }

    @ApiOperation(value = "根据id获取",notes="根据id获取")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long ")
    @GetMapping("/{id}")
    public Result<Order> orderGetById(@PathVariable Long id) {
        return Result.ok(orderService.getById(id));
    }

    @ApiOperation(value = "添加",notes="新增")
    @PostMapping("")
    public Result<Boolean> orderSave(@RequestBody @Valid  Order order) {
        return Result.ok(orderService.save(order));
    }

    @ApiOperation(value = "修改",notes="根据id修改")
    @PutMapping("/{id}")
    public Result<Boolean> orderUpdate(@RequestBody @Valid  Order order, @PathVariable Long id) {
        order.setId(id);
        return Result.ok(orderService.updateById(order));
    }

    @ApiOperation(value = "删除",notes="根据id删除")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long ")
    @DeleteMapping("/{id}")
    public Result<Boolean> orderDelete(@PathVariable Long id) {
        return Result.ok(orderService.removeById(id));
    }


}
